﻿package com.moonshineproject.plugin.project.vo.flash {
	import com.moonshineproject.utils.TextUtil;
	
	import flash.filesystem.File;
	public class SWFOutputVO 
	{
		public var path:File;
		public var frameRate:Number = 24;
		public var swfVersion:uint = 10;
		public var width:int = 100;
		public var height:int = 100;
		
		/** Background color */
		public var background:uint;
		
		
		public function toString():String {
			return "[SWFOutput path='"+path.nativePath+"' frameRate='"+frameRate+"' swfVersion='"+swfVersion+"' width='"+width+"' height='"+height+"' background='#"+backgroundColorHex+"']";
		}
		public function get backgroundColorHex():String {
			return TextUtil.padLeft(background.toString(16).toUpperCase(), 6);
		}
		
		/*
			Returns XML representation of this class.
			If root is set you will get relative paths
		*/
		public function toXML(pathsRelativeTo:String):XML
		{
			var output:XML = <output/>;
			
			var pathAsString:String = "";
			// Can we do a relative path?
			if (path && pathsRelativeTo 
				&& path.nativePath.length > pathsRelativeTo.length)
			{
				// +1 to discard first slash
				pathAsString = path.nativePath.substring(pathsRelativeTo.length+1)	
			} 
			
			var outputPairs:Object = {
				'fps'		:	frameRate,
				'path'		:	pathAsString,
				'width'		:	width,
				'height'	:	height,
				'version'	:	swfVersion,
				'background':	backgroundColorHex,
				'disabled'	: 	'False'
			};
			
			for (var i:String in outputPairs) 
			{
				var node:XML = <movie/>
				node.@[i] = outputPairs[i];
				output.appendChild(node);
			}
			
			return output;
		}
		
	}
}